﻿<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:CreaMotion_UserControls="clr-namespace:CreaMotion.UserControls" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:CreaMotionConverters="clr-namespace:CreaMotion.ValueConverters" xmlns:ee="http://schemas.microsoft.com/expression/2010/effects" xmlns:ed="http://schemas.microsoft.com/expression/2010/drawing"
	x:Class="CreaMotion.Forms.RelationshipDesignForm"
	x:Name="Window1"
	Width="632" Height="444" ResizeMode="NoResize" mc:Ignorable="d" Title="Table Relationships">
	<Window.Resources>
		<CreaMotionConverters:String2RelationshipType x:Key="String2RelationshipType"/>
		<CreaMotionConverters:FieldItem2String x:Key="FieldItem2String" />
		<CreaMotionConverters:Bool2String x:Key="Bool2String" />
		<CreaMotionConverters:BoolToVisibility x:Key="boolToVis" />

		<Style TargetType="{x:Type TextBlock}" 
			x:Key="GridBlockStyle">
			<Setter Property="VerticalAlignment" Value="Center" />
			<Setter Property="Visibility" 
				Value="{Binding IsSelected, ConverterParameter=False, Converter={StaticResource boolToVis}, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}}}" />
		</Style>

		<Style TargetType="{x:Type FrameworkElement}" 
			x:Key="GridEditStyle">
			<Setter Property="VerticalAlignment" Value="Center" />
			<Setter Property="Visibility" 
				Value="{Binding IsSelected, ConverterParameter=True, Converter={StaticResource boolToVis}, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}}}" />
		</Style>

    </Window.Resources>

    <Grid x:Name="LayoutRoot">
		<Grid Height="83.334" Margin="2,1.5,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="624">
            <ComboBox x:Name="cmbSecoundTable" Margin="279,23,0,21.667" HorizontalAlignment="Left" Width="250.667"/>
            <ComboBox x:Name="cmbFirstTable"  Margin="8,23,0,21.667" HorizontalAlignment="Left" Width="250.667" d:LayoutOverrides="HorizontalAlignment"/>
			<TextBlock Height="15" Margin="8,4,0,0" TextWrapping="Wrap" VerticalAlignment="Top" HorizontalAlignment="Left" Width="71"><Run Text="First Table "/><Run Language="tr-tr" Text=":"/></TextBlock>
			<TextBlock Height="15" Margin="279,4,250,0" TextWrapping="Wrap" VerticalAlignment="Top" Text="Second Table :"/>
		</Grid>
		<Rectangle Fill="#FF39A30A" Height="4" Margin="0,71,0,0" Stroke="Black" VerticalAlignment="Top"/>
		<TextBlock HorizontalAlignment="Left" Height="14" Margin="2,79,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="80"><Run Language="tr-tr" Text="Relationships :"/></TextBlock>
        
		<ListView ItemsSource="{Binding relationships, ElementName=Window1}" x:Name="ListRelationships" Margin="0,96,0,0" d:IsLocked="True">
			<ListView.View> 
				<GridView>
					<GridViewColumn Header="First Field" Width="132" >
					<GridViewColumn.CellTemplate>
						<DataTemplate>
                                <Grid>
                                    <TextBlock Text="{Binding FirstField, Converter={StaticResource FieldItem2String}}" Style="{StaticResource GridBlockStyle}" />
                                    <ComboBox SelectedItem="{Binding FirstField}" ItemsSource="{Binding firstTableFields, ElementName=Window1}" Style="{StaticResource GridEditStyle}"
										  Width="115" />
                                </Grid>
                            </DataTemplate>
					</GridViewColumn.CellTemplate>
					</GridViewColumn>
					 <GridViewColumn Header="Type" Width="130">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <Grid>
                                    <TextBlock Text="{Binding FirstFieldType, Converter={StaticResource Bool2String}}" Style="{StaticResource GridBlockStyle}" />
                                    <ComboBox Text="{Binding FirstFieldType}" SelectedItem="{Binding FirstFieldType, Converter={StaticResource String2RelationshipType}}" Width="115" Style="{StaticResource GridEditStyle}"  >
                                        <sys:String>One</sys:String>
                                        <sys:String>Many</sys:String>
                                    </ComboBox>
                                </Grid>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
					<GridViewColumn Header="Secound Field" Width="132">
					<GridViewColumn.CellTemplate>
						<DataTemplate>
                                <Grid>
                                    <TextBlock Text="{Binding SecoundField, Converter={StaticResource FieldItem2String}}" Style="{StaticResource GridBlockStyle}" />
                                    <ComboBox SelectedItem="{Binding SecoundField}" ItemsSource="{Binding secoundTableFields, ElementName=Window1}" Style="{StaticResource GridEditStyle}"
										      Width="115" />
                                </Grid>
                            </DataTemplate>
					</GridViewColumn.CellTemplate>
					</GridViewColumn>
                    <GridViewColumn Header="Type" Width="130">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <Grid>
                                    <TextBlock Text="{Binding SecoundFieldType, Converter={StaticResource Bool2String}}" Style="{StaticResource GridBlockStyle}" />
                                    <ComboBox Text="{Binding SecoundFieldType}" SelectedItem="{Binding SecoundFieldType, Converter={StaticResource String2RelationshipType}}" Width="115" Style="{StaticResource GridEditStyle}" >
                                        <sys:String>One</sys:String>
                                        <sys:String>Many</sys:String>
								    </ComboBox>
                                </Grid>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                </GridView>
			</ListView.View>
		</ListView>
    	<Button Margin="0,167.644,0,204.156" Style="{DynamicResource SpecialButton}" Foreground="White" FontSize="18.667" HorizontalAlignment="Right" Width="102.667" Background="Black">
    		<TextBlock Margin="-11,-3.999,-12.749,-3.547" TextWrapping="Wrap" Text="Remove" d:IsLocked="True"/>
    	</Button>
    	<Button x:Name="btAddRelationship" Margin="0,121.444,0,0" Style="{DynamicResource SpecialButton}" Foreground="White" FontSize="18.667" HorizontalAlignment="Right" Width="102.667" Height="46.2" VerticalAlignment="Top" Background="Black">
    		<Button.BorderBrush>
    			<LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
    				<GradientStop Color="#FFCCCCCC" Offset="0"/>
    				<GradientStop Color="#FF413A3A" Offset="1"/>
    			</LinearGradientBrush>
    		</Button.BorderBrush>
    		<TextBlock Margin="0,-3.999,13.251,-3.547" TextWrapping="Wrap" d:IsLocked="True"><Run Language="tr-tr" Text="Add"/></TextBlock>
    	</Button>
    	<Button x:Name="btClearRelationship" Margin="0,0,0,156.956" Style="{DynamicResource SpecialButton}" Foreground="White" FontSize="18.667" HorizontalAlignment="Right" Width="102.667" Height="46.2" VerticalAlignment="Bottom" Background="Black">
    		<TextBlock Margin="-10,-3.999,-12.749,-3.547" TextWrapping="Wrap" Text="Clear" d:IsLocked="True"/>
    	</Button>
    	<Button x:Name="btCloseForm" Style="{DynamicResource SpecialButton}" Foreground="White" FontSize="18.667" HorizontalAlignment="Right" Width="102.667" Height="46.2" VerticalAlignment="Bottom" Background="#FF700D0D">
    		<TextBlock Margin="-14,-3.999,-7.416,-3.547" TextWrapping="Wrap" Text="Close" d:IsLocked="True"/>
    	</Button>
    	<Button x:Name="btSaveRelationship" Style="{DynamicResource SpecialButton}" Foreground="White" FontSize="18.667" HorizontalAlignment="Right" Width="102.667" Height="46.2" VerticalAlignment="Bottom" Margin="0,0,0,47.2" Background="#FF0F7E2A">
    		<TextBlock Margin="-10,-3.999,-12.749,-3.547" TextWrapping="Wrap" Text="Save" d:IsLocked="True"/>
    	</Button>
		
    </Grid>
</Window>